package com.firmiana.jt809;


import com.firmiana.jt809.netty.main.NettyTCPMainLink;
import com.firmiana.jt809.service.Listener;
import com.firmiana.jt809.task.sub.SubTaskService;
import com.firmiana.jt809.util.SpringUtils;
import org.springframework.context.ApplicationContext;

import java.util.Arrays;

/**
 * @author hucl
 * @date 2020/8/26 17:05
 */
public class JT809Launcher {
    private static NettyTCPMainLink mainLink;
    private static SubTaskService subTaskService;

    public static void launch(ApplicationContext context, int port, String host) {
        mainLink = new NettyTCPMainLink(port, host);
        mainLink.init();
        subTaskService = context.getBean(SubTaskService.class);
    }

    public static void start() {
        mainLink.start(new Listener() {
            @Override
            public void onSuccess(Object... args) {
                System.out.println("【主链路】启动成功。端口号：" + Arrays.toString(args));
            }

            @Override
            public void onFailure(Throwable cause) {
                System.out.println("【主链路】启动失败。" + cause);
            }
        });
//        subTaskService.start();
    }
}
